<template>
  <div class="app-container">
    <el-form :model="settings" ref="form" size="small" :inline="true" label-width="110px">

      <el-row>
        <h3>提现条件</h3>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="最小提现金额" prop="minprice">
            <el-input type="number" min="0" v-model="settings.minprice" placeholder="请输入最小金额">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="最大提现金额" prop="maxprice">
            <el-input type="number" min="0" v-model="settings.maxprice" placeholder="请输入最大金额">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="每天可提现" prop="withdrawnumperday">
            <el-input type="number" min="0" v-model="settings.withdrawnumperday" placeholder="请输入每天可提现次数">
              <template slot="append">次</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="每月可提现" prop="withdrawnumpermonth">
            <el-input type="number" min="0" v-model="settings.withdrawnumpermonth" placeholder="请输入每月可提现次数">
              <template slot="append">次</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitSettings">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { getLastSetting,addSetting,updateSetting } from "@/api/smy/distributionSetting";

export default {
  name: "settings",
  data() {
    return {
      // 遮罩层
      loading: true,
      settings:{},
      // 显示搜索条件
      showSearch: true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        minprice: [
          { required: true, message: "最小提现金额不能为空", trigger: "blur" }
        ],
        maxprice: [
          { required: true, message: "最大提现金额不能为空", trigger: "blur" }
        ],
        withdrawnumperday: [
          { required: true, message: "每天可提现次数不能为空", trigger: "blur" }
        ],
        withdrawnumpermonth: [
          { required: true, message: "每月可提现次数不能为空", trigger: "blur" }
        ],
        recommend: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        salesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        postage: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        postagetype: [
          { required: true, message: "$comment不能为空", trigger: "change" }
        ],
        havesku: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        gram: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        bargainprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        bargainstore: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        marketingtype: [
          { required: true, message: "$comment不能为空", trigger: "change" }
        ],
        bargainstatus: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        bargainsalesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        seckillprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        seckillsalesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        seckillstatus: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        seckillstore: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        presellprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        presellsalesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        presellstatus: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingcondition: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookinglimit: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingsalesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingstatus: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingtotal: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingstore: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        issupplier: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        affiliatedunitvalue: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        havemultiunit: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        ultimateunitvalue: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        supplierpostage: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        supplierpostagetype: [
          { required: true, message: "$comment不能为空", trigger: "change" }
        ],
        recommendsupplier: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        isissuingtype: [
          { required: true, message: "$comment不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getSettings();
  },
  methods: {
    getSettings(){
      this.loading = true;
      getLastSetting().then(response => {
        const settings = response.data;
        this.settings = settings;
        this.loading = false;
      });
    },
    submitSettings(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          console.log(this.settings);
          if (this.settings.id != null) {
            updateSetting(this.settings).then(response => {
              this.$modal.msgSuccess("提交成功");
              this.getSettings();
            });
          } else {
            addSetting(this.form).then(response => {
              this.$modal.msgSuccess("提交成功");
              this.getSettings();
            });
          }
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateGoods(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGoods(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  }
};
</script>
